﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using HighThroughput.ShareData;
using OSSUtility;
using OSSUtility.Devices;
using OSSUtility.Models;
using Ozone.Models;

namespace Ozone.Device
{

    /// <summary>
    /// 机械臂离心机旁边机械臂
    /// </summary>
    public class DevRobotByCentrifugalMachine
    {


        //机械臂设备
        public static DevRebot_SR3 devRebot;

        /// <summary>
        /// 连接到机械臂 AGV和视觉 
        /// </summary>
        /// <param name="Message"></param>
        /// <returns></returns>
        public bool Connection(out string Message)
        {
            Message = string.Empty;
            bool IsConnection = false;
            try
            {
                #region 连接初始化机械臂
                devRebot = new DevRebot_SR3("192.168.0.161", Utility.str2int("8080"));
                bool po = devRebot.OpenConn(Utility.str2int("8081"));
                if (po)
                {
                    //机械臂连接成功后自动初始化
                    bool Startpo = devRebot.Start();
                    if (!Startpo)
                    {
                        Message = "机械臂初始化失败请检查机械臂是否急停或者手动控制中";
                        IsConnection = false;
                        return IsConnection;
                    }
                    else
                    {
                        IsConnection = true;
                    }
                }
                else
                {
                    IsConnection = false;
                    Message = "机械臂连接失败!";
                    return IsConnection;
                }
                #endregion
            }
            catch (Exception ex)
            {
                IsConnection = false;
                Message = ex.Message;
            }
            return IsConnection;
        }





        /// <summary>
        /// 获取当前点位
        /// </summary>
        /// <returns></returns>
        public string GetCurPos()
        {
            PointXYZ polocation = devRebot.GetCurPos();

            string lacation = polocation.X.ToString() + "," + polocation.Y.ToString() + "," + polocation.Z.ToString() +
                 "," + polocation.A.ToString() + "," + polocation.B.ToString() + "," + polocation.C.ToString();

            return lacation;
        }

    }
}
